export function formatNumber (n) {
  const str = n.toString()
  return str[1] ? str : `0${str}`
}

export function formatTime (date) {
  const year = date.getFullYear()
  const month = date.getMonth() + 1
  const day = date.getDate()

  const hour = date.getHours()
  const minute = date.getMinutes()
  const second = date.getSeconds()

  const t1 = [year, month, day].map(formatNumber).join('/')
  const t2 = [hour, minute, second].map(formatNumber).join(':')

  return `${t1} ${t2}`
}

export function formatTime2 (date) {
  const year = date.getFullYear()
  const month = date.getMonth() + 1
  const day = date.getDate()

  let weekday = new Array(7)
  weekday[0] = '周日'
  weekday[1] = '周一'
  weekday[2] = '周二'
  weekday[3] = '周三'
  weekday[4] = '周四'
  weekday[5] = '周五'
  weekday[6] = '周六'

  const t1 = `${year}年${month}月${day}日 ${weekday[date.getDay()]}`

  return t1
}

export function mGetDate (year, month) {
  let d = new Date(year, month, 0)
  return d.getDate()
}
